import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

public class Game extends JFrame implements ActionListener {
    Random r = new Random();
    JButton start = new JButton("开始");
    public Game(){
        initJFrame();
        initView();
    }
    public void initJFrame(){
        this.setSize(500,600);
        this.setTitle("抽签");
        this.setAlwaysOnTop(true);
        this.setLocationRelativeTo(null);
        this.setLayout(null);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setVisible(true);
    }
    public void initView(){
        start.setBounds(200,250,100,40);
        start.addActionListener(this);
        this.getContentPane().add(start);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        Object source = e.getSource();
        if(source == start){
            int n = r.nextInt(4) ;
            if(n == 0){
                showJDialog("鸡哥");
            } else if (n == 1) {
                showJDialog("星爷");
            }else if (n == 2) {
                showJDialog("明哥");
            }else if (n == 3) {
                showJDialog("车");
            }
        }
    }
    public void showJDialog(String content){
        //创建一个弹窗对象
        JDialog jDialog = new JDialog();
        //设置大小
        jDialog.setSize(400,150);
        //弹框置顶
        jDialog.setAlwaysOnTop(true);
        //居中
        jDialog.setLocationRelativeTo(null);
        //不关闭无法进行其他的操作
        jDialog.setModal(true);

        //创建JLabel对象
        JLabel warning = new JLabel(content);
        warning.setBounds(0,0,200,150);
        jDialog.getContentPane().add(warning);

        //展示
        jDialog.setVisible(true);
    }
}
